package com.xps.charmingshop.view.fragment;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;

import com.jude.utils.JUtils;
import com.xps.charmingshop.App;
import com.xps.charmingshop.adapter.ConductAdapter;
import com.xps.charmingshop.bean.ConductBean;
import com.xps.charmingshop.date.net.UserNetWorks;
import com.xps.charmingshop.utils.ListDividerItemDecoration;
import com.xps.charmingshop.utils.SharedPreferencesUtils;
import com.xps.charmingshop.view.base.BaseSwipeRefreshFragment;

import java.util.List;

import rx.Subscriber;


/**
 * Created by MI on 2018/1/10.
 */

public class ConductFragment extends BaseSwipeRefreshFragment {

    @Override
    public void onClick(View v) {

    }

    @Override
    protected void getData(int pageIndex) {

    }

    @Override
    public void onResume() {
        super.onResume();
        doMore();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        ListDividerItemDecoration list = new ListDividerItemDecoration((int) (1 * getActivity().getResources().getDisplayMetrics().density));
        recyclerView.addItemDecoration(list);
        setRefreshEnable(false);
        abstractRecyclerAdapter = new ConductAdapter(App.getInstance(), recyclerView);
        abstractRecyclerAdapter.setAutoLoadMoreEnable(true);
        doMore();
        super.onActivityCreated(savedInstanceState);
    }

    void doMore() {
        String user_token = SharedPreferencesUtils.getString("user_token", "String", null);
        UserNetWorks.getOrder(user_token, new Subscriber<ConductBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
            }

            @Override
            public void onNext(ConductBean tongZhiBean) {
                List<ConductBean.ReturnBodyBean> list = tongZhiBean.getReturn_body();
                if (list != null && list.size() <= 0) {
                    onFail("没有更多");
                    return;
                }
                adapterListData = list;
                onResponce();
            }
        });
    }

    public void hide() {
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.hide(this);
        fragmentTransaction.commit();
    }
}
